package com.qf.purchase.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.purchase.po.City;
import com.qf.purchase.po.Provice;
import com.qf.purchase.service.CityService;
import com.qf.purchase.service.ProviceService;
import com.qf.purchase.utils.Region;
import com.qf.purchase.utils.LayUIOperate;
import com.qf.purchase.utils.TableData;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Copyright (C),2022
 * FileName: RegionController
 * Author: ding
 * Date:2022/5/7 11:14
 */
@Controller
@RequestMapping("/region")
public class RegionController {
    @Resource
    CityService cityService;
    @Resource
    ProviceService proviceService;

    @RequestMapping("/city")
    @ResponseBody
    public String getCity(HttpServletRequest request){
        String pname=request.getParameter("pname");
        Map map=new HashMap();
        map.put("pname",pname);
        List<Region> list=cityService.getAllCityByPage(map).getList();
        String city= JSON.toJSON(list).toString();
        return city;
    }
    @RequestMapping("/provice")
    @ResponseBody
    public String getProvice(){
        List<Provice> provices=proviceService.getAllProviceByPage(new HashMap());
        String city= JSON.toJSON(provices).toString();
        return city;
    }


    @RequestMapping("/getCityByprovice")
    @ResponseBody
    public String getCityByprovice(HttpServletRequest request){
        String pname=request.getParameter("pname");
        Provice provice=proviceService.getProviceByName(pname);
        Map map=new HashMap();
        map.put("pId",provice.getId());
        List<Region> list=cityService.getAllCityByPage(map).getList();
        String city= JSON.toJSON(list).toString();
        return city;
    }
} 
